<?php

/**
 * @author Nick  Swartelé
 */

require_once 'Gebruiker.php';
require_once '/db/Database.php';

class Applicatie {
    
    public function Homepage(){
        echo "Welkom op de Homepage van RoboTik!";
   }
    
    public function Ingelogd(){

        if ($_SESSION['Recht_id'] == 1) { 
            echo "Producten beheren"; echo "<br />";
            echo "Berichten";
        }
        
           if ($_SESSION['Recht_id'] == 2) { 
            echo "Berichten"; echo "<br />";
        }
     
 else {     
          header('Location: index.php?app=ingelogd');
     
     }
 } 
    public function Login() {
        
        if (isset($_POST['submit'])){
            if (!empty ($_POST['username']))
             
            $db = new Database;
            $db->checkLogin($_POST['username'],$_POST['password']);
            $gebruiker = $db->getObject();
                       
            session_start();
            $_SESSION['userName'] =  $gebruiker->getuserName();
            $_SESSION['Recht_id'] =  $gebruiker->getRecht_id();
            
          header('Location: index.php?app=ingelogd');
    }
    
    else
    {
            echo " <form id='login' action='' method='post' accept-charset='UTF-8'>
        <table>

            <tr> <td> <label for='username' >Username</label> </td>  <td>  <input type='text' name='username' id='username'  maxlength='50' /> </td> </tr>
            <tr> <td><label for='password' >Paswoord</label> </td> <td><input type='password' name='password' id='password' maxlength='50' /> </td> </tr>
            <tr> <td> <input type='submit' name='submit' value='Submit' /> <td></tr>

        </table>
    </form>";
        } 
    }

    
    public function Registreren(){
       
           if (isset($_POST['submit'])){
              
            $db = new Database;
            $db->addGeregistreerdeGebruiker($_POST['username'], $_POST['password'], $_POST['email'], $_POST['secret_question'], $_POST['secret_answer']);    
    }
    else
        {
        
    
        echo ("<form action ='' method ='post'>
                    <table>
                        <tr>
                            <td><label for='username'>Gebruikersnaam:</label></td>
                            <td><input name='username' type='text' /></td>
                        </tr>
                        <tr>
                            <td><label for='password'>Gewenst Wachtwoord:</label></td>
                            <td><input name='password' type='password' /></td>
                        </tr>
                        <tr>
                            <td><label for='email'>E-mail</label></td>
                            <td><input name='email' type='text' /></td>
                        </tr>
                        <tr>
                            <td><label for='Secret_Question'>Geheime vraag:</label></td>
                            <td><input name='secret_question' type='text' /></td>
                           
                        </tr>
                        <tr>
                            <td><label for='Secret_Answer'>Geheim Antwoord:</label></td>
                            <td><input name='secret_answer' type='text'/></td>
                         </tr>
                        <tr>
                            <td> <input type='submit' name='submit' id='knoppen' value='Registreren' alt='toevoegen' /> </td>
                        </tr>
                    </table><br/>     
                </form>");
        }
    }
    
        public function Robottoevoegen(){
        
        
           if (isset($_POST['submit'])){
              
            $db = new Database;
            $db->addNieuweRobot($_POST['artikel_nummer'], $_POST['artikel_naam'], $_POST['programmeerbaar'], $_POST['opvoorraad'], $_POST['fabrikant_nummer']);    
   
            echo "<pre>";
            var_dump($db);
            echo"</pre>";
            
            
            }
    else
        {
        
    
        echo ("<form action ='' method ='post'>
                    <table>
                    <center><h1> Robot toevoegen </h1></center>
                        <tr>
                            <td><label for='artikel_nummer'>Artikelnummer:</label></td>
                            <td><input name='artikel_nummer' type='text' /></td>
                        </tr>
                        <tr>
                            <td><label for='artikel_naam'>Artikelnaam:</label></td>
                            <td><input name='artikel_naam' type='text' /></td>
                        </tr>
                        <tr>
                            <td><label for='programmeerbaar'>Programmeerbaar:</label></td>
                            <td><input name='programmeerbaar' type='text' /></td>

                        </tr>
                        <tr>
                            <td><label for='opvoorraad'>Op voorraad:</label></td>
                            <td><input name='opvoorraad' type='text' /></td>
                           
                        </tr>
                        <tr>
                            <td><label for='fabrikant_nummer'>Fabrikantnummer:</label></td>
                            <td><input name='fabrikant_nummer' type='text'/></td>
                         </tr>
                        <tr>
                            <td> <input type='submit' name='submit' id='knoppen' value='Robot toevoegen' alt='toevoegen' /> </td>
                        </tr>
                    </table><br/>     
                </form>");
        }
    }
}

?>
